import com.qi.dao.UserMapper;
import com.qi.pojo.User;
import com.qi.utils.MyBatisUtils;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;
import org.junit.Test;

import java.util.HashMap;
import java.util.List;


/**
 * @author zjq
 * @date 2020/3/11 15:46
 */
public class UserMapperText {

    static Logger logger = Logger.getLogger(UserMapperText.class);

    @Test
    public void findUser() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        logger.info("sqlSession进入findUser（）成功");
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        User userList = mapper.getUserById(1);
        System.out.println(userList);

        //select * from mybatis.user where id=#{id}
        //类型处理器
        //select id,name,pwd from mybatis.user where id=#{id}
        sqlSession.close();
    }

    @Test
    public void LogTest() {
        logger.info("info:进入了log4j");
        logger.debug("debug:进入了log4j");
        logger.error("error:进入了log4j");
    }

    @Test
    public void ByLimit() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        HashMap<String, Integer> map = new HashMap<String, Integer>();

        map.put("startIndex", 0);
        map.put("pageSize", 2);
        List<User> userList = mapper.getUserByLimit(map);
        for (User user : userList) {
            System.out.println(user);
        }


        sqlSession.close();
    }

    @Test
    public void ByRowBounce() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        RowBounds rowBounds = new RowBounds(1, 2);
        List<User> list = sqlSession.selectList("com.qi.dao.UserMapper.getUserByRowBounce", null, rowBounds);
        for (User user : list) {
            System.out.println(user);
        }
        sqlSession.close();
    }
}
